const express = require('express');
const app = express();
const cors = require('cors')
const router = require('./router/index')

// 配置全局变量 app.js作用域下所有文件都可以访问common中的db和RunSQL
// require(process.cwd() + '/src/db/sql.js');
// require(process.cwd() + '/src/db/utils.js');

app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cors())

app.use('/downIMG', express.static('./downIMG'));
app.use('/static', express.static('./static'));
app.use(router)

const server = app.listen(8081, () => {
    const host = server.address().address
    const port = server.address().port
    console.log("应用实例，访问地址为 http://%s:%s", host.length > 4 ? host : '127.0.0.1', port)
}).on('error', res => console.log('出错了', res))